package com.hjli.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hjli.model.LinkInfo;
import com.hjli.service.impl.LinkService;

@Controller
@RequestMapping("sys/link")
public class LinkController {

	@Resource
	LinkService linkService;
	@RequestMapping("save")
	public @ResponseBody Map<String,Object> save(HttpServletRequest request,HttpServletResponse response){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		LinkInfo link = new LinkInfo();
		if(request.getParameter("linkName")==null||request.getParameter("linkName").toString()==""){
			resultMap.put("result", "友链昵称不能为空");
			return resultMap;
		}
		if(request.getParameter("linkAddress")==null||request.getParameter("linkAddress").toString()==""){
			resultMap.put("result", "友链地址不能为空");
			return resultMap;
		}
		link.setlName(request.getParameter("linkName"));
		link.setlUrl(request.getParameter("linkAddress"));
		link.setlClickNum(0);
		if(request.getParameter("linkIcon")==null||request.getParameter("linkIcon").toString()==""){
			link.setlIconAdress("");
		}
		link.setlIconAdress(request.getParameter("linkIcon"));
		if(request.getParameter("linkSort")==null||request.getParameter("linkSort").toString()==""){
			link.setlSort(10);
		}
		link.setlSort(Integer.parseInt(request.getParameter("linkSort")));
		
		if(linkService.insert(link)==1){
			resultMap.put("result", "success");
		}else{
			resultMap.put("result", "添加失败");
		}
		return resultMap;
	}
}
